package controller

import (
	"context"
	"mini-app/config/redis"
	"mini-app/internal/define"
	"time"

	"github.com/gin-gonic/gin"
)

func GetOpenID(c *gin.Context) string {
	token := c.GetHeader("Authorization")
	if token == "" {
		return ""
	}
	rdb := redis.NewDB()
	// 获取会话参数
	timeoutCtx, cancel := context.WithTimeout(c.Request.Context(), time.Second*3)
	defer cancel()
	openid, _ := rdb.Get(timeoutCtx, define.MiniAppSessionOpenid+token).Result()
	return openid
}
